package week;

import java.time.temporal.WeekFields;
import java.util.*;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-08 22:19
 **/
public class Week3 {

    public long minimumRemoval(int[] beans) {
        Arrays.sort(beans);
        long sum = 0;
        for (int bean : beans) {
            sum += bean;
        }

        long min = Long.MAX_VALUE;
        int n = beans.length;
        for (int i = 0; i < n; ++i) {
            //以当前元素为基准所需要的操作数(需要移除掉当前元素前的所有元素,并将后面的元素移到和当前元素一样的个数,即只剩下(n - i) * beans[i]个豆子所需要的移除数目)
            min = Math.min(sum - (long) (n - i) * beans[i], min);
        }
        return min;
    }

    public String subStrHash(String s, int power, int modulo, int k, int hashValue) {
        List<Character> list = new LinkedList<>();
        int n = s.length();
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            list.add(c);

            if (i >= k - 1) {
                long p = 1;
                long hashVal = 0;
                for (char ccc : list) {
                    hashVal += (p * (ccc - 'a' + 1)) % modulo;
                    p = p * power % modulo;
                }

                if (hashVal % modulo == hashValue) {
                    for (char cc : list) {
                        res.append(cc);
                    }
                    return res.toString();
                }
                list.remove(0);
            }
        }
        return "666";
    }


    /*public int wordCount(String[] startWords, String[] targetWords) {
        HashSet<Integer> set = new HashSet<>();
        for (String word : startWords) {
            int mask = 0;
            for (char c : word.toCharArray()) {
                mask |= 1 << c - '0';
            }
            set.add(mask);
        }
        int count = 0;
        for (String word : targetWords) {
            int mask = 0;
            for (char c : word.toCharArray()) {
                mask |= 1 << c - '0';
            }
            for (char c : word.toCharArray()) {
                if (set.contains(mask ^ (1 << c - '0'))) {
                    count++;
                    break;
                }
            }
        }
        return count;
    }*/

}
